import {fromJS} from "immutable";
import {chang_login_account_input, update_login_or_register_state, update_title_index} from "../../body/contants";

const defaultState = fromJS({
    headerList: [
        {title: "首页", link: "/index", id: 1},
        {title: "项目", link: "/project", id: 2},
        {title: "体系", link: "/system", id: 3},
        {title: "公众号", link: "/public", id: 4},
        {title: "导航", link: "/nav", id: 5},
        {title: "项目分类", link: "/cls", id: 6},
        {title: "工具", link: "/tool", id: 7},
    ],
    currentIndex: 0,
    showLoginView: false,  //展示登录界面
    showRegisterView: false, //展示注册界面

    loginAccountValue: "",
    loginPwdValue: "",
    registerAccountValue: "",
    registerPwdValue: "",
    registerRepeatValue: "",
});


export default (status = defaultState, action) => {
    switch (action.type) {
        case update_title_index:
            return status.set("currentIndex", action.index);

        case update_login_or_register_state:
            return status.merge({
                showLoginView: action.showState,
                showRegisterView: action.registerState
            });
        case chang_login_account_input:

            return changeInputValue(status,action);
        default:
            return status;
    }
}

const changeInputValue = (status, action) => {
        const inputTag = action.inputTag;
        if (action.tag) {
            return inputTag === 0 ? status.set("loginAccountValue", action.inputValue) : status.set("loginPwdValue", action.inputValue)
        } else {
            switch (inputTag) {
                case 0:
                    return status.set("registerAccountValue", action.inputValue);
                case 1:
                    return status.set("registerPwdValue", action.inputValue);
                case 2:
                    return status.set("registerRepeatValue", action.inputValue);
                default:
                    return status;
            }
        }
    }
;